/**
 * 大厅模块
 * @author none
 */
class MainSceneView extends how.module.Scene 
{
    //文本
    public userCoin: how.Label;//玩家金币
    public userName: how.Label;//玩家昵称
    //图片
    public topBg: eui.Image;//顶部背景
    public bannerBg: eui.Image;//轮播图背景
    // public logoLight: eui.Image;//logo光环

    //按钮
    public btnLanguage: how.Button;//语言选择
    public btnSetting: how.Button;//设置按钮
    public btnscreen: how.Button;//全屏按钮
    public btnHeader: eui.Image;//玩家头像
    private kindList: eui.List;

    public static AllowReportChildren: Array<any> = ["kindListItem"];
    public constructor() 
    {
        super();
        this.skinName = "MainSceneSkin";
        DataConfig.SetResConfig(); // 初始化游戏需要资源
    }

    public get resourceList(): Array<string> 
    {
        return ["public", "game_hall"];
    }

    public start(): void 
    {
        this.updateHeader();
        this.updateMoney();
        this.updateNickname();
        this.updateGamePeople();
        this.initEvent();
    }

    // 动态展示房间列表
    private showKindList(itemDatas: any): void
    {
        this.kindList.dataProvider = new eui.ArrayCollection(itemDatas);
    }

    //更新积分
    private updateMoney(): void 
    {
        this.userCoin.text = base.Utils.formatCurrency(AppData.getInstance().userData.money);
    }

    //更新头像
    public updateHeader(): void 
    {
        this.btnHeader.source = AppData.getInstance().userData.gender == 1 ?
            "man" + AppData.getInstance().userData.gender + "_png" : "women" + AppData.getInstance().userData.gender + "_png";
    }

    //更新玩家昵称
    public updateNickname() 
    {
        this.userName.text = how.StringUtils.format(this.userName.text, base.Utils.formatNickName(D.App.userData.nickName/*AppData.getInstance().userData.accounts*/, 10));
    }

    //监听事件
    public initEvent() 
    {
        this.btnSetting.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onSettingClick, this);
        this.btnLanguage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onLanguageClick, this);
        this.btnHeader.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onHeaderClick, this);
        this.btnscreen.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onBtnscreen, this);
    }

    /*--------------------------人数---------------------------------- */
    private updateGamePeople() 
    {
        let gameList = AppData.getInstance().gameList, len = gameList.length;
        for (let i = 0; i < len; i++) 
        {
            if (isNaN(gameList[i].count)) return;
            if (this["game" + gameList[i].id + "Item"]) 
            {
                this["game" + gameList[i].id + "Item"]["game" + gameList[i].id + "People"].text = "" + gameList[i].count;
            }
        }
    }

    /*--------------------------按钮响应----------------------------- */
    //按下玩家头像
    public onHeaderClick(): void 
    {
        this.report(MainSceneModule.request.onHeader);
    }

    //按下设置按钮
    public onSettingClick(): void 
    {
        this.report(MainSceneModule.request.onSetting);
    }

    //语言按钮
    private onLanguageClick(): void 
    {
        how.Alert.show("暂时只提供中文版本");
    }

    //按下全屏按钮
    private onBtnscreen(): void 
    {
        if (window["screenfull"].enabled) {
            window["screenfull"].toggle();
        }
    }

    //销毁
    public onDestroy(): void 
    {
        egret.Tween.removeAllTweens();
    }
}

window["MainSceneView"] || (window["MainSceneView"] = MainSceneView);
